import { Modal } from 'antd';
import React, { Component } from 'react';
import { fetchData } from '../../../components/AjaxConsumer';
import WorkAreaForm from './UpdateForm';

const confirm = Modal.confirm;

export default class UpdateWorkareaPage extends Component {
    constructor(props) {
        super(props);
        this.state = {
            loading: false,
            formTitle: '',
            visible: false,
            resData: {},
            submitUrl: '/base/workarea/c'
        };
    }

    //显示弹框
    showModal = () => {
        this.setState({
            visible: true,
        });
    }
    // 隐藏弹出框
    hideModal = () => {
        this.setState({
            visible: false,
        });
    }

    editGetInfoCallBack = (resData) => {
        console.log("修改数据：\n", JSON.stringify(resData, null, 4));
        console.log("修改数据：\n", resData.data);
        this.setState(
            {
                submitUrl: '/material/insidewarehouse/RawStorageSn/updatePE',
                resData: resData.data[0],
                isEdit: true,
                formTitle: '修改PE管长度'
            }
        );
        this.showModal();//显示弹框
    }

    // 编辑信息
    editHandle = (rowObj) => {
        //根据对象的Id 属性获取对象信息
        let barcode = rowObj[0].data.barcode;
        let contractNo = rowObj[0].data.contractNo;
        let model = rowObj[0].data.model;
        let modelType = rowObj[0].data.modelType;
        let wlCode = rowObj[0].data.wlCode;
        const options = {
            url: '/material/insidewarehouse/RawStorageSn/r/detailPost',
            type: 'post',
            condition: {
                barcode: barcode,
                // model:model,
                // modelType:modelType,
                // wlCode:wlCode,
            },
        };

        console.log("====222222222222====");
        fetchData(this, options, this.editGetInfoCallBack);
    }

    // 新增/修改后的回调
    handleOk = () => {
        this.hideModal();
        this.refreshHandle();
    }

    handleCancel = () => {
        //表单重置
        this.refs.modalFrom.resetFields();
        this.hideModal();
    }

    //刷新List列表
    refreshHandle = () => {
        console.log("刷新List列表")
        this.props.refreshHandle();
    }

    render() {
        if (this.state.resData != null && this.state.resData.data != null) {
            let factory = this.state.resData.data;
            this.getFormData.map((e, index) => {
                e.initialValue = factory[e.name]
            });
        }

        return (
            <Modal
                style={{ top: '20px' }}
                visible={this.state.visible}
                title={this.state.formTitle ? this.state.formTitle : '填写表单'}
                onOk={this.handleOk}
                onCancel={this.handleCancel}
                width={'850px'}
                footer=''
            >

                <WorkAreaForm
                    ref="modalFrom"
                    isEdit={this.state.isEdit}
                    submitUrl={this.state.submitUrl}
                    onCancel={this.handleCancel}
                    factoryCode="all"
                    formData={this.state.resData}
                    refreshHandle={this.refreshHandle}
                />

            </Modal>
        )
    }
}